from django.db import models
import datetime
from django.utils import timezone
# Create your models here.

class tmManager(models.Manager):
    def save_tm(self, data):
        try:
            test_tm_info.objects.create(
                ask_name=data.get('ask_name'),
                ans_A=data.get('ans_A'),
                ans_B=data.get('ans_B'),
                ans_C=data.get('ans_C'),
                ans_D=data.get('ans_D'),
                ans_sucess=data.get('ans_sucess'),
                operator=data.get('username'),
            )
            result = {'result': True, 'message': u"保存成功"}
        except Exception as e:
            result = {'result': False, 'message': u"保存失败, %s" % e}
        return result

class test_tm_info(models.Model):
    # 题库
    ask_name=models.CharField(u'试题题目',max_length=500,error_messages={"required": "该字段不能为空!"})
    ans_A=models.CharField(u'答案A',max_length=100)
    ans_B=models.CharField(u'答案B',max_length=100)
    ans_C=models.CharField(u'答案C',max_length=100)
    ans_D=models.CharField(u'答案D',max_length=100)
    ans_sucess=models.CharField(u'正确答案',max_length=100,error_messages={"required": "该字段不能为空!"})
    ask_info=models.CharField(u'试题备注信息',max_length=500)
    insert_time=models.DateField(u'保存时间',default=timezone.now())
    operator = models.CharField(u"记录人", max_length=64)
    objects=tmManager()

